﻿using System;
using System.Collections.Generic;

namespace ASP.NetAjaxApplication.Models
{
    public static class DummyData
    {
        static Random rnd = new Random();

        public static string GenText(int length = 20)
        {
            var dictionary = new string[] { };
            if (dictionary.Length == 0)
            {
                var loremText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus a nunc et felis egestas ullamcorper vitae ac lectus. Aliquam erat volutpat. Curabitur a nisl egestas, lobortis erat eu, malesuada nibh. Integer pharetra mi velit, pellentesque ornare ligula egestas vel. Quisque elit ipsum, viverra ut sollicitudin in, varius ac dolor. Nulla consectetur lectus vel dolor commodo pulvinar. Fusce ut accumsan lectus. Cras gravida rutrum nibh vitae adipiscing. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Curabitur fringilla sem viverra faucibus adipiscing. Nulla id ultricies elit, eu pharetra dui. Suspendisse sit amet adipiscing nunc. Quisque sit amet tortor nisi.Vivamus vel malesuada erat. Quisque accumsan augue id imperdiet tempor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sodales est ac ipsum interdum, in luctus erat tempus. Vestibulum non aliquam leo. Nullam vehicula massa risus, at vestibulum dui porta vitae. Proin in tempus nunc, sed sodales turpis.Donec et aliquam quam. Duis dapibus mauris sit amet egestas euismod. Phasellus augue orci, molestie non gravida interdum, porttitor at nibh. Nunc id nisl at purus elementum mattis. Duis enim magna, placerat id mi et, elementum tincidunt enim. Praesent at aliquam arcu. Sed sed tincidunt dolor. Proin a posuere ipsum.Proin vel tellus eu enim interdum vulputate et blandit mi. Nulla sed ornare risus, fermentum cursus massa. Donec et fermentum massa. Praesent tincidunt orci suscipit justo porta venenatis. Ut eleifend lectus et sem dapibus, vel sollicitudin est venenatis. Phasellus id vulputate lectus. Nunc placerat purus at consectetur dignissim. In placerat odio in tortor vehicula, in varius sem molestie. Nam vitae justo venenatis, sollicitudin nulla at, interdum enim. Quisque iaculis, nibh ut volutpat porttitor, justo neque sollicitudin nisi, id eleifend turpis sem eu dolor. Phasellus ut feugiat quam. Suspendisse bibendum nunc quis arcu fringilla varius vitae quis orci. Nulla congue in magna non vehicula.Praesent dictum erat nisi, mattis tincidunt velit gravida vitae. Maecenas quis purus feugiat, volutpat quam id, vulputate diam. Nulla non ultrices leo, sagittis adipiscing odio. Pellentesque nec felis dictum, congue lorem vitae, dictum nisi. Sed vitae dolor in libero adipiscing fermentum. Phasellus est magna, pellentesque et orci eu, tincidunt rhoncus urna. Morbi ac mi semper, luctus arcu ac, cursus dui. Proin laoreet lobortis erat ut semper. Cras sagittis egestas tortor eu gravida. Morbi pulvinar vel ante et tincidunt. Sed sit amet diam lobortis, aliquet mauris et, egestas tellus. Proin ultrices malesuada mi, quis dictum dui iaculis vel. Nam consequat tempus ante at malesuada. Nulla facilisi. Aliquam condimentum, urna ut feugiat ultricies, magna metus ultrices nibh, vitae malesuada nulla tellus tristique massa.";
                dictionary = loremText.Split(".".ToCharArray());
            }

            var index = rnd.Next(0, dictionary.Length - 1);
            return (dictionary[index].Substring(0, dictionary[index].Length > length ? length : dictionary[index].Length - 1)).Trim();
        }

        public static IEnumerable<NodeModel> CreateRules()
        {
            var tree = new List<NodeModel>();

            for (int i = 0; i < 10; i++)
            {
                var p = new NodeModel();
                p.key = Guid.NewGuid().ToString();
                p.title = string.Format("Rule {0}", i);
                p.tooltip = string.Format("This is tooltip of node has key {0}", p.key);

                var children = new List<NodeModel>();
                for (int j = 10 - i; j < 10; j++)
                {
                    var c = new NodeModel();
                    c.key = Guid.NewGuid().ToString();
                    c.title = string.Format("Rule {0} - {1}", i, j);
                    c.tooltip = string.Format("This is tooltip of node has key {0}", p.key);

                    children.Add(c);
                }
                p.children = children;
                p.expand = rnd.Next(0, 2) == 1;
                tree.Add(p);
            }

            return tree;
        }

        public static IEnumerable<NodeModel> CreateList(int numberOfItem = 4)
        {
            var tree = new List<NodeModel>();

            for (int i = 0; i < numberOfItem; i++)
            {
                var p = new NodeModel();
                p.key = Guid.NewGuid().ToString();
                p.title = string.Format("List {0}", i);
                p.tooltip = string.Format("This is tooltip of node has key {0}", p.key);

                var children = new List<NodeModel>();
                for (int j = 10 - i; j < 10; j++)
                {
                    var c = new NodeModel();
                    c.key = Guid.NewGuid().ToString();
                    c.title = string.Format("List {0} - {1}", i, j);
                    c.tooltip = string.Format("This is tooltip of node has key {0}", p.key);
                    c.select = rnd.Next(0, 2) == 1;
                    children.Add(c);
                }
                p.children = children;
                p.select = rnd.Next(0, 2) == 1;
                p.expand = rnd.Next(0, 2) == 1;
                tree.Add(p);
            }

            return tree;
        }

        public static IEnumerable<AdditionalQuestionModel> CreateListAddtionalQuestions(int numberOfItem = 10)
        {
            var list = new List<AdditionalQuestionModel>();

            for (int i = 0; i < numberOfItem; i++)
            {
                var item = new AdditionalQuestionModel
                               {
                                   Id = rnd.Next(1000, 9999),
                                   Description = GenText()
                               };
                list.Add(item);
            }

            return list;
        }

        public static IEnumerable<AddonModel> CreateListAddons(int numberOfItem = 10)
        {
            var list = new List<AddonModel>();

            for (int i = 0; i < numberOfItem; i++)
            {
                var item = new AddonModel
                {
                    Id = rnd.Next(1000, 9999),
                    Description = GenText(),
                    Quantity = rnd.Next(0, 20),
                    Code = string.Format("Code - {0}", rnd.Next(100, 999)),
                    Price = rnd.Next(1000, 9999)
                };
                list.Add(item);
            }

            return list;
        }

        public static IEnumerable<LineItemModel> CreateListLineItems(int numberOfItem = 10)
        {
            var list = new List<LineItemModel>();

            for (int i = 0; i < numberOfItem; i++)
            {
                var item = new LineItemModel
                {
                    Id = i,
                    Code = string.Format("Code - {0}", rnd.Next(20, 100)),
                    Description = GenText(),
                    Quantity = rnd.Next(0, 20),
                    Height = rnd.Next(100, 200),
                    Width = rnd.Next(50, 100),
                    Depth = rnd.Next(10, 30),
                    Hinge = "Left Right",
                    FE = "None"
                };

                item.AdditionalQuestions = DummyData.CreateListAddtionalQuestions(rnd.Next(0, 4));
                item.Addons = DummyData.CreateListAddons(rnd.Next(0, 3));

                list.Add(item);
            }

            return list;
        }

        private static List<NodeModel> listClients = null;
        public static IEnumerable<NodeModel> CreateListClients(int numberOfItem = 10)
        {
            if (listClients !=null)
            {
                return listClients;
            }

            listClients = new List<NodeModel>();

            var dealerKey = Guid.NewGuid().ToString();
            var clientId = Guid.NewGuid().ToString();
            for (int i = 0; i < numberOfItem; i++)
            {
                var c = new ClientModel
                            {
                                ClientName = "Client Name " + i,
                                JobName = "Job Name " + i,
                                PONumber = rnd.Next(100000,999999),
                                Room = "Kitchen " + i,
                                DealerId = new Guid(dealerKey),
                                ClientId = new Guid(clientId)
                            };
                //Level: Dealer name
                var dealer = new NodeModel
                                 {
                                     key = dealerKey,
                                     title = GenText(10),
                                     icon = "client.png"
                                 };
                //Level: Client name
                var client = new NodeModel
                {
                    key = clientId,
                    title = c.ClientName,
                    icon = "client.png",
                    expand = true,
                    data = c
                };

                //Level: PO
                var po = new NodeModel
                {
                    key = dealerKey,
                    title = string.Format("{0} - {1}", c.JobName, c.PONumber),
                    icon = false,
                    expand = true,
                    data = c
                };

                //Level: Order Name
                var on = new NodeModel
                {
                    key = dealerKey,
                    title = c.Room + " - M",
                    icon = false,
                    data = c
                };

                po.children = new List<NodeModel>{on};
                client.children = new List<NodeModel> { po };
                dealer.children = new List<NodeModel> { client };

                listClients.Add(dealer);
            }

            return listClients;
        }

        private static List<string> listRecentQuotes = null;
        public static IEnumerable<string> CreateListRecentQuotes(int numberOfItem = 10)
        {
            if (listRecentQuotes != null)
            {
                return listRecentQuotes;
            }
            
            listRecentQuotes = new List<string>();
            for (var i = 0; i < numberOfItem; i++)
            {
                var name = GenText();
                var number = rnd.Next(100000, 999999);
                listRecentQuotes.Add(string.Format("{0} - {1}", name, number));
            }
            return listRecentQuotes;
        }

        public static List<HeaderModel> CreateOrderHeader()
        {
            var header = new List<HeaderModel>();

            header.Add(new HeaderModel
                           {
                               Products = "Style Line",
                               Choises = new Choise { Name = "Encore" }
                           });

            header.Add(new HeaderModel
            {
                Products = "Bold Material",
                Choises = new Choise { Name = "Plywood Edge Tape" },
                Price = "19%",
                Quantity = "4",
                Total = "544.73"
            });

            
            header.Add(new HeaderModel
            {
                Products = "Box Options"
            });

            header.Add(new HeaderModel
            {
                Choises = new Choise { Checked = true, Name = "Plywood Shelves" }
            });

            header.Add(new HeaderModel
            {
                Choises = new Choise { Checked = true, Name = "Plywood Ends" },
                Price = "60.00",
                Quantity = "7",
                Total = "420.00"
            });

            header.Add(new HeaderModel
            {
                Products = "Upper Door",
                Choises = new Choise { Name = "Wood" }
            });

            header.Add(new HeaderModel
            {
                Products = "Lower Door",
                Choises = new Choise { Name = "Country Classic - Full Overlay" },
                Price = "104.00",
                Quantity = "0",
                Total = "0"
            });

            header.Add(new HeaderModel
            {
                Products = "Outside Reveal",
                Choises = new Choise { Name = "PF" }
            });

            header.Add(new HeaderModel
            {
                Products = "Drawer Font",
                Choises = new Choise { Name = "D1 Slab" },
                Price = "0",
                Quantity = "0"
            });

            header.Add(new HeaderModel
            {
                Products = "Drawer Box",
                Choises = new Choise { Name = "3/4 Dovetail Soft Close Full Ext" },
                Price = "126.00",
                Quantity = "4",
                Total = "504.00"
            });

            header.Add(new HeaderModel
            {
                Products = "Wood Specie",
                Choises = new Choise { Name = "Clerry" },
                Price = "0%"
            });

            header.Add(new HeaderModel
            {
                Products = "Finish Process",
                Choises = new Choise { Name = "Stain" }
            });

            header.Add(new HeaderModel
            {
                Products = "Finish Color",
                Choises = new Choise { Name = "Raisin" },
                Price = "3%",
                Total = "137.94"
            });

            header.Add(new HeaderModel
            {
                Products = "Sheen Level",
                Choises = new Choise { Name = "Standard" },
                Price = "0%",
                Total = "0.00"
            });

            header.Add(new HeaderModel
            {
                Price = "Subtotal 1",
                Total = "2,906.00"
            });

            header.Add(new HeaderModel
            {
                Price = "Subtotal 2",
                Total = "4,598.00"
            });

            header.Add(new HeaderModel
            {
                Price = "List Total",
                Total = "5,556.55"
            });

            header.Add(new HeaderModel
            {
                Price = "Net Price",
                Quantity = "*10",
                Total = "5.556.55"
            });

            header.Add(new HeaderModel
            {
                Price = "Freight",
                Total = "122.16"
            });

            header.Add(new HeaderModel
            {
                Price = "Tax",
                Total = "3.91"
            });

            header.Add(new HeaderModel
            {
                Price = "Total Delivered Cost",
                Total = "5882.62"
            });


            return header;
        }
    }
}